import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;


// we override this in case we need to do something temporarily

public class PLTempEventQueue extends EventQueue {
	boolean mInit = false;
	
	public PLTempEventQueue() {		
	}

	protected void finalize() {
		Shutdown();
	}

	public void Init() {
		// this overrides the event queue to make this the default event queue
		if (!mInit) {
			Toolkit.getDefaultToolkit().getSystemEventQueue().push(this);
			mInit = true;
		}
	}

	public void Shutdown() {
		// this will cause this event queue to stop and return to previous queue 
		if (mInit) {
			this.pop();	
			mInit = false;
		}
	}

	// dispatches the next event in the queue
	public void DispatchNextEvent() {
		try {
			AWTEvent event = this.getNextEvent();
			dispatchEvent(event);
		} catch (NullPointerException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void dispatchEvent(AWTEvent event) {
		// the only functionality I add is that I print out all the events		
		super.dispatchEvent(event);
	}
	
}

